﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using Infragistics.Win.UltraWinGrid;

namespace DMSClient.General
{
    public partial class EmailGroup : Form
    {
        EndpointAddress address;
        DataSet ds;
        DataSet dsItem;
        DataTable dtDistributor;
        UltraDropDown uddDistributors;
        WSHttpBinding Binding = new WSHttpBinding();
        string ambiente;
        public EmailGroup()
        {
            InitializeComponent();            
            ambiente = Properties.Settings.Default.CurrentEnv;
            Binding.MaxReceivedMessageSize = 2147483647;
            Binding.MaxBufferPoolSize = 2147483647;
            Binding.ReceiveTimeout = TimeSpan.MaxValue;
            Binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            Binding.Security.Mode = SecurityMode.None;
            address = new EndpointAddress(Properties.Settings.Default.Server);

            this.Text = Properties.Settings.Default.CurrentEnvDes + " - Email Group";

              
           
        }

        private void EmailGroup_Load(object sender, EventArgs e)
        {
            ugItems.Enabled = false;
            
            WorkerGroup.RunWorkerAsync();
            estado(false);
        }


        #region CONSULTA DE GRUPOS
        private void WorkerGroup_DoWork(object sender, DoWorkEventArgs e)
        {
            DMSServices.DMSServicesClient client;
            client = new DMSServices.DMSServicesClient(Binding, address);
            string groups = null;
            string distributor = null;
            try
            {
                client.Open();
                groups = client.getEmailGroups(); 
                distributor = client.getDistribuitorsListWhitCountries();
                client.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(Properties.Settings.Default.DistributorsListErrorMsg, ex.InnerException);
            }
            if (groups == null)
            {
                throw new Exception(Properties.Settings.Default.DistributorsNullListErrorMsg);
            }

            DataTable dt = new DataTable("dtEmailGroups");
            dt.Columns.Add("IdEmailGroup");
            dt.Columns.Add("DsName");


            dtDistributor = new DataTable("dtDistList");
            dtDistributor.Columns.Add("IdCountry");
            dtDistributor.Columns.Add("dsCountry");
            dtDistributor.Columns.Add("IdDistributor");
            dtDistributor.Columns.Add("cdDistributor");
            dtDistributor.Columns.Add("dsName");
            dtDistributor.Columns.Add("dsCorporateName");
            dtDistributor.Columns.Add("idStatus");
            dtDistributor.Columns.Add("SendAlerts");

            ds = new DataSet();
            ds.Tables.Add(dt);
            ds.Tables.Add(dtDistributor);

            System.IO.StringReader xmlSR = new System.IO.StringReader(groups);
            ds.ReadXml(xmlSR, XmlReadMode.ReadSchema);
            xmlSR.Close();

            System.IO.StringReader xmlSR1 = new System.IO.StringReader(distributor);
            ds.ReadXml(xmlSR1, XmlReadMode.ReadSchema);
            xmlSR1.Close();

        }

        private void WorkerGroup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (!this.IsDisposed)
                {
                    this.BringToFront();
                    MessageBox.Show(this, e.Error.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    estado(true);
                }
            }
            else if (!e.Cancelled && !this.IsDisposed)
            {
                ugGroups.DataSource = ds.Tables[0];
                ugGroups.DisplayLayout.Bands[0].Columns["IdEmailGroup"].Hidden = true;
                ugGroups.DisplayLayout.Bands[0].Columns["DsName"].Width = 200;
                BindUltraDropDown();
                if (ds.Tables[0].Rows.Count != 0)
                {
                    DeleteGroup.Visible = true;
                }
                else
                {
                    DeleteGroup.Visible = false;
                }
                estado(true);
                 
            }
            
            
        }
        #endregion

        public void estado(bool estado)
        {
            ugGroups.Enabled = estado;
            ugItems.Enabled = estado;           
            loader.Visible = !estado;

        }

        private void EmailGroup_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (WorkerGroup.IsBusy)
            {
                WorkerGroup.CancelAsync();
            }
            if (WorkerItem.IsBusy) 
            {
                WorkerItem.CancelAsync();
            }
        }

        private void EmailGroup_Resize(object sender, EventArgs e)
        {
            loader.Left = (this.Width - loader.Width) / 2;
            loader.Top = ((this.Height - loader.Height) / 2) - loader.Height;
        }

        private void EmailGroup_Shown(object sender, EventArgs e)
        {
            loader.Left = (this.Width - loader.Width) / 2;
            loader.Top = ((this.Height - loader.Height) / 2) - loader.Height;
        }

        private void ugGroups_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            foreach (UltraGridBand bands in e.Layout.Bands)
            {
                foreach (UltraGridColumn ugc in bands.Columns)
                {
                    ugc.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, true);
                }
            }
        }
        #region CONSULTAR ITEM DE UN GRUPO
        private void ugGroups_AfterRowActivate(object sender, EventArgs e)
        {
          
            if (WorkerGroup.IsBusy)
            {
                WorkerGroup.CancelAsync();
            }

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow && !row.Cells["IdEmailGroup"].Value.ToString().Equals(""))
                {
                    WorkerItem.RunWorkerAsync();
                    estado(false);
                    break;
                }
            /*    else 
                {
                
                }*/
            }

            validarBotonDeleteGroup();
            
        }
        private void WorkerItem_DoWork(object sender, DoWorkEventArgs e)
        {
            DMSServices.DMSServicesClient client;
            client = new DMSServices.DMSServicesClient(Binding, address);
            int idGroup = -1;

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    idGroup = int.Parse(row.Cells["IdEmailGroup"].Value.ToString());
                    break;
                }
            }
            string groups = null;
            try
            {
                if (idGroup != -1)
                {
                    client.Open();
                    groups = client.getEmailGroupsItems(idGroup);
                    client.Close();
                }
                else 
                {
                    WorkerItem.WorkerSupportsCancellation = true;
                    WorkerItem.CancelAsync();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(Properties.Settings.Default.DistributorsListErrorMsg, ex.InnerException);
            }
            if (groups == null)
            {
               throw new Exception(Properties.Settings.Default.DistributorsListErrorMsg);
            }
            
                DataTable dt = new DataTable("dtEmailGroupItems");
                dt.Columns.Add("idEmailGroup");
                dt.Columns.Add("idDistributor");

                dsItem = new DataSet();
                dsItem.Tables.Add(dt);

                System.IO.StringReader xmlSR = new System.IO.StringReader(groups);
                dsItem.ReadXml(xmlSR, XmlReadMode.ReadSchema);
                xmlSR.Close();
            
        }

        private void WorkerItem_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (!this.IsDisposed)
                {
                    this.BringToFront();
                    MessageBox.Show(this, e.Error.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    estado(true);
                }
            }
            else if (!e.Cancelled && !this.IsDisposed)
            {
                ugItems.DataSource = dsItem.Tables[0];
                ugItems.DisplayLayout.Bands[0].Columns["idDistributor"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;
                ugItems.DisplayLayout.Bands[0].Columns["idEmailGroup"].Hidden = true;
                ugItems.DisplayLayout.Bands[0].Columns["idDistributor"].Width = 200;
               // ugItems.DisplayLayout.Bands[0].Override.CellClickAction = CellClickAction.RowSelect;
               
                if (dsItem.Tables[0].Rows.Count != 0)
                {
                   DeleteItem.Visible = true;
                }
                else
                {
                  DeleteItem.Visible = false;
                }
                estado(true);


            }
        }
        #endregion

        private void BindUltraDropDown()
        {
            try
            {
                
                uddDistributors = new UltraDropDown();

                uddDistributors.SetDataBinding(ds.Tables[1], null);
                uddDistributors.DisplayLayout.Bands[0].Columns["dsCountry"].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
                uddDistributors.DisplayLayout.Bands[0].Columns["idStatus"].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
                uddDistributors.DisplayLayout.Bands[0].Columns["SendAlerts"].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
                uddDistributors.DisplayLayout.Bands[0].Columns["IdDistributor"].Hidden = true;
                uddDistributors.DisplayLayout.Bands[0].Columns["dsCorporateName"].Hidden = true;
                uddDistributors.DisplayLayout.Bands[0].Columns["dsName"].Hidden = true;
                uddDistributors.DisplayLayout.Bands[0].Columns["cdDistributor"].Width = 200;
                uddDistributors.DisplayLayout.Bands[0].Columns["IdCountry"].Hidden = true; 
                uddDistributors.ValueMember = "IdDistributor";
                uddDistributors.DisplayMember = "cdDistributor";
       //         uddDistributors.Enabled = false;
                
            }
            catch (Exception ex) { }
        }

        private void ugItems_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            foreach (UltraGridBand bands in e.Layout.Bands)
            {
                foreach (UltraGridColumn ugc in bands.Columns)
                {
                    ugc.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, true);
                }
            }
            e.Layout.Bands[0].Columns["idDistributor"].ValueList = this.uddDistributors;
        }

        private void ultraButton4_Click(object sender, EventArgs e)
        {
            int count = 0;       
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {

                if (row.Cells["DsName"].Value.ToString().Equals(""))
                {
                    count++;
                }
            }
            if (count > 0)
            {
                MessageBox.Show("There are empty rows, delete or complete these rows", "Group");
            }
            else
            {
                try
                {
                    ugGroups.Rows.Band.AddNew();

                    int tam = ugItems.Rows.Count;
                    while (tam !=0)
                    {
                        ugItems.Rows[tam-1].Selected = true;
                        ugItems.Rows[tam-1].Delete(false);
                        tam--; 
                       
                    }
                    validarBotonDeleteGroup();
                     
                }
                catch (Exception exc) { }
            }
           
        }

        private void ultraButton3_Click(object sender, EventArgs e)
        {
            int count = 0;
            bool FilaActiva = false;
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    FilaActiva = true;
                }
            }
            if (FilaActiva)
            {
                foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows)
                {


                    if (row.Cells["idDistributor"].Value.ToString().Equals(""))
                    {
                        count++;
                    }


                }
                if (count > 0)
                {
                    MessageBox.Show("There are empty rows, delete or complete these rows", "Item");
                }
                else
                {
                    uddDistributors.Enabled = true;
                    ugItems.Rows.Band.AddNew();
                }
            }
            else
            {
                MessageBox.Show("Please , choose a Distributor!");
            }
        }
        #region SAVE
        private void ultraButton2_Click(object sender, EventArgs e)
        {
            bool swGroup = false;
            bool swGroupItem = false;
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row != null)
                {
                    if (validateGroup(row))
                    {
                        swGroup = true;
                    }
                    else 
                    {
                        swGroup = false;
                    }
                }

            }
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in  ugItems.Rows)
            {
                if (row != null)
                {
                    if (validateGroupItem(row))
                    {
                        swGroup = true;
                    }
                    else
                    {
                        swGroup = false;
                    }
                }

            }

            if (swGroup)
            {
                estado(false);
                WorkerSave.RunWorkerAsync();
            }
        }

        private void WorkerSave_DoWork(object sender, DoWorkEventArgs e)
        {

            DMSServices.DMSServicesClient client;
            client = new DMSServices.DMSServicesClient(Binding, address);

            List<Dtl.EmailGroup> listEmailGroup = new List<Dtl.EmailGroup>();
            List<Dtl.EmailGroupItem> listEmailGroupItem = new List<Dtl.EmailGroupItem>();

            //GUARDO EN LA LISTA DE GRUPOS
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row != null)
                {
                    Dtl.EmailGroup EmailGroup = new Dtl.EmailGroup();
                    EmailGroup.dsName = row.Cells["DsName"].Value.ToString();

                    if (row.Cells["idEmailGroup"].Value.ToString().Equals(""))
                    {
                        EmailGroup.typeOperation = true;
                    }
                    else
                    {
                        EmailGroup.typeOperation = false;
                        EmailGroup.idEmailGroup = int.Parse(row.Cells["idEmailGroup"].Value.ToString());
                    }

                    listEmailGroup.Add(EmailGroup);


                }

            }
            int idGroup = -1;
            bool sendAlert = false;

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow && !row.Cells["idEmailGroup"].Value.ToString().Equals(""))
                {
                    idGroup = int.Parse(row.Cells["idEmailGroup"].Value.ToString());
                     
                    break;
                }
            }
            if (idGroup != -1)
            {
                //GUARDO EN LA LISTA DE ITEMS DE GRUPOS
                foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows)
                {
                    if (row != null && row.Cells["idEmailGroup"].Value.ToString().Equals(""))
                    {
                        Dtl.EmailGroupItem EmailGroupItem = new Dtl.EmailGroupItem();
                        EmailGroupItem.idDistributor = int.Parse(row.Cells["idDistributor"].Value.ToString());
                        EmailGroupItem.idEmailGroup = idGroup;
                        EmailGroupItem.typeOperation = true;
                        listEmailGroupItem.Add(EmailGroupItem);

                    }

                }
            }
             
                try
                {
                    client.Open();
                    int resul = client.setEmailGroup(listEmailGroup, listEmailGroupItem);
                    if (resul == 1)
                    {
                        MessageBox.Show("Successfully saved record!", "Email Group");

                    }
                    else
                    {
                        MessageBox.Show("Error saving the record, please try again!", "Email Group");
                    }
                    client.Close();
                    if (WorkerSave.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex.InnerException);
                }
            

        }

        private void WorkerSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (!this.IsDisposed)
                {
                    this.BringToFront();
                    MessageBox.Show(this, e.Error.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    estado(true);
                }
            }
            else if (!e.Cancelled && !this.IsDisposed)
            {
                estado(true);
                WorkerGroup.RunWorkerAsync();
            }
        }

        #endregion

        #region VALIDATE
        private bool validateGroup(UltraGridRow row)
        {
            if (row.Cells["DsName"].Value.ToString().Equals(""))
            {
                MessageBox.Show("Please choose field DsName");
                return false;
            }
            return true;
        
        }
        private bool validateGroupItem(UltraGridRow row)
        {
            if (row.Cells["idDistributor"].Value.ToString().Equals(""))
            {
                MessageBox.Show("Please choose field idDistributor");
                return false;
            }
            return true;

        }
        #endregion
        #region DELETE ITEM
        private void DeleteItem_Click(object sender, EventArgs e)
        {
            bool FILA = false;
            string id = "";
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows)
            {
                if (row.IsActiveRow)
                {
                    FILA = true;
                    id = row.Cells["idDistributor"].Text;
                }
            }
            if (FILA)
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                string caption = "GROUP ITEM";
                string mensaje = "Do You're  sure that want to delete the record '" + id + "'?";
                DialogResult resultado = MessageBox.Show(mensaje, caption, buttons);


                if (resultado == DialogResult.Yes)
                {
                    estado(false);
                    WorkerDeleteItem.RunWorkerAsync();
                }
            }
            else
            {

                MessageBox.Show("Please, choose you a row of FTP/SFTP to deleted!", "FTP");
            }
        }

        private void WorkerDeleteItem_DoWork(object sender, DoWorkEventArgs e)
        {
            DMSServices.DMSServicesClient client;
            client = new DMSServices.DMSServicesClient(Binding, address);
            int IdGroup = -1;
            int IdGroupItem = -1;
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    IdGroup = int.Parse(row.Cells["idEmailGroup"].Value.ToString());

                }
            }

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows)
            {
                if (row.IsActiveRow)
                {
                    IdGroupItem = int.Parse(row.Cells["idDistributor"].Value.ToString());
                    break;
                }
            }

            if (IdGroup != -1 && IdGroupItem != -1)
            {
                try
                {
                    client.Open();
                    if (client.DeleteEmailGroupItem(IdGroup,IdGroupItem) == 1)
                    {
                        MessageBox.Show("Successfully deleted record!", "GROUP ITEM");

                    }
                    else
                    {
                        MessageBox.Show("Error deleted the record, please try again!", "GROUP ITEM");
                    }
                    client.Close();
                    if (WorkerDeleteGroup.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex.InnerException);
                }

            }
            else
            {
                MessageBox.Show("Error deleted the record, please try again!", "FTP");
            }
        }

        private void WorkerDeleteItem_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (!this.IsDisposed)
                {
                    this.BringToFront();
                    MessageBox.Show(this, e.Error.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    estado(true);
                }
            }
            else if (!e.Cancelled && !this.IsDisposed)
            {
                estado(true);
                WorkerItem.RunWorkerAsync();
            }
        }
        #endregion

        #region DELETE GROUP
        private void DeleteGroup_Click(object sender, EventArgs e)
        {
            bool FILA = false;
            string id = "";
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    FILA = true;
                    id = row.Cells["DsName"].Value.ToString();
                }
            }
            if (FILA)
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                string caption = "GROUP";
                string mensaje = "Do You're  sure that want to delete the record " + id + "?";
                DialogResult resultado = MessageBox.Show(mensaje, caption, buttons);


                if (resultado == DialogResult.Yes)
                {
                  estado(false);
                  WorkerDeleteGroup.RunWorkerAsync();
                }
            }
            else
            {

                MessageBox.Show("Please, choose you a row of Group to deleted!", "FTP");
            }
        }

        private void WorkerDeleteGroup_DoWork(object sender, DoWorkEventArgs e)
        {
            DMSServices.DMSServicesClient client;
            client = new DMSServices.DMSServicesClient(Binding, address);
            int IdGroup = -1;
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    IdGroup = int.Parse(row.Cells["idEmailGroup"].Value.ToString());
                    break;
                }
            }


            if (IdGroup != -1)
            {
                try
                {
                    client.Open();
                    if (client.DeleteEmailGroup(IdGroup) == 1)
                    {
                        MessageBox.Show("Successfully deleted record!", "GROUP");

                    }
                    else
                    {
                        MessageBox.Show("Error deleted the record, please try again!", "GROUP");
                    }
                    client.Close();
                    if (WorkerDeleteGroup.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex.InnerException);
                }

            }
            else
            {
                MessageBox.Show("Error deleted the record, please try again!", "GROUP");
            }
        }

        private void WorkerDeleteGroup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                if (!this.IsDisposed)
                {
                    this.BringToFront();
                    MessageBox.Show(this, e.Error.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    estado(true);
                }
            }
            else if (!e.Cancelled && !this.IsDisposed)
            {
                estado(true);
                WorkerGroup.RunWorkerAsync();
            }
        }

        #endregion

        private void ubCancel_Click(object sender, EventArgs e)
        {
            WorkerGroup.RunWorkerAsync();
            estado(false);
        }

        private void ugGroups_AfterRowFilterChanged(object sender, AfterRowFilterChangedEventArgs e)
        {            
            UltraGridRow firstVisibleRow = this.ugGroups.Rows.GetRowAtVisibleIndex(0);
            firstVisibleRow.Cells["IdEmailGroup"].Activate();
        }

        private void ugItems_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
        {
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows) 
            {
                if (row.IsActiveRow)
                {
                    if (row.Cells["idEmailGroup"].Value.ToString().Equals(""))
                    {
                        DeleteItem.Visible = false;

                    }
                    else
                    {
                        DeleteItem.Visible = true;
                    }
                }
            }
        }

        private void ugGroups_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
        {
            validarBotonDeleteGroup();
        }

        private void validarBotonDeleteGroup() 
        {

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugGroups.Rows)
            {
                if (row.IsActiveRow)
                {
                    if (row.Cells["IdEmailGroup"].Value.ToString().Equals(""))
                    {
                        DeleteGroup.Visible = false;
                        addEmailRow.Visible = false;
                        DeleteItem.Visible = false;
                        int tam = ugItems.Rows.Count;
                        while (tam != 0)
                        {
                            ugItems.Rows[tam - 1].Selected = true;
                            ugItems.Rows[tam - 1].Delete(false);
                            tam--;

                        }
                    }
                    else
                    {
                        DeleteGroup.Visible = true;
                        addEmailRow.Visible = true;
                        DeleteItem.Visible = true;
                    }
                }
            }
        
        }

        private void ugItems_AfterRowActivate(object sender, EventArgs e)
        {
            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ugItems.Rows)
            {
                if (row.IsActiveRow)
                {
                    if (row.Cells["idEmailGroup"].Value.ToString().Equals(""))
                    {
                        DeleteItem.Visible = false;
                    }
                    else
                    {
                        DeleteItem.Visible = true;
                    }
                }
            }
        }



        

    }
}
